package com.alinesno.cloud.common.web.base.config;

import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import com.google.common.collect.Maps;

/**
 * 添加thymeleaf全局变量
 * 
 * @author WeiXiaoJin
 * @since 2019年12月22日 下午9:24:15
 */
public class ThymeleafConfig {
	
	private static final Logger log = LoggerFactory.getLogger(ThymeleafConfig.class) ; 

	@Resource
    private Environment env;

	/**
	 * 配置全局路径
	 * @param viewResolver
	 */
	@Resource
    private void configureThymeleafStaticVars(ThymeleafViewResolver viewResolver) {
        if(viewResolver != null) {
            Map<String, Object> vars = Maps.newHashMap();
           
            String globalCDN = env.getProperty("alinesno.global.cdn") ; 
            log.debug("global_cdn:{}" , globalCDN);
            
            if(StringUtils.isEmpty(globalCDN)) {
            	globalCDN = "" ; 
            }
            
			vars.put("cdn", globalCDN);
            
            viewResolver.setStaticVariables(vars);
        }
    }

}
